﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="三分厂费用分配表.aspx.cs" Inherits="syc.ChengBen.三分厂.三分厂费用分配表" %>
<%@ Import  Namespace="System.Data"%>
<%@ Import  Namespace="System.Data.SqlClient"%>
<%@ Import  Namespace="System.Configuration"%>
<html>
<head runat="server">
    <title>三分厂费用归集分配表</title>
</head>
<body>
<script runat =server>
    protected double 合计;
    protected double 套管金额合计;
    protected double 套管单位费用合计;    
    protected double 油管金额合计;
    protected double 油管单位费用合计;
    protected double 套管累计金额合计;
    protected double 套管累计单位费用合计;
    protected double 油管累计金额合计;
    protected double 油管累计单位费用合计;
    protected double 套管产量;
    protected double 套管累计产量;
    protected double 油管产量;
    protected double 油管累计产量;
    protected int part1Count;
    protected int part2Count;
    protected int part3Count;
    protected int part4Count;
    protected void Button1_Click(object sender, EventArgs e)
    {
        string part1 = @"<html xmlns:o='urn:schemas-microsoft-com:office:office'
xmlns:x='urn:schemas-microsoft-com:office:excel'
xmlns='http://www.w3.org/TR/REC-html40'>

<head>
<meta http-equiv=Content-Type content='text/html; charset=utf-8'>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>Chinese User</o:Author>
  <o:LastAuthor>Chinese User</o:LastAuthor>
  <o:LastPrinted>2011-05-27T07:18:33Z</o:LastPrinted>
  <o:Created>2011-05-26T03:35:39Z</o:Created>
  <o:LastSaved>2011-05-27T07:19:32Z</o:LastSaved>
  <o:Company>Chinese ORG</o:Company>
  <o:Version>11.9999</o:Version>
 </o:DocumentProperties>
</xml><![endif]-->
<style>
<!--table
	{mso-displayed-decimal-separator:'\.';
	mso-displayed-thousand-separator:'\,';}
@page
	{margin:.13in .1in 1.0in .41in;
	mso-header-margin:.18in;
	mso-footer-margin:.5in;
	mso-page-orientation:landscape;}
tr
	{mso-height-source:auto;
	mso-ruby-visibility:none;}
col
	{mso-width-source:auto;
	mso-ruby-visibility:none;}
br
	{mso-data-placement:same-cell;}
.style0
	{mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	white-space:nowrap;
	mso-rotate:0;
	mso-background-source:auto;
	mso-pattern:auto;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	border:none;
	mso-protection:locked visible;
	mso-style-name:常规;
	mso-style-id:0;}
td
	{mso-style-parent:style0;
	padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	border:none;
	mso-background-source:auto;
	mso-pattern:auto;
	mso-protection:locked visible;
	white-space:nowrap;
	mso-rotate:0;}
.xl24
	{mso-style-parent:style0;
	font-size:10.0pt;}
.xl25
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl26
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:left;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl27
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:right;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl28
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl29
	{mso-style-parent:style0;
	font-size:18.0pt;
	text-align:center;
	vertical-align:bottom;}
.xl30
	{mso-style-parent:style0;
	mso-number-format:'Long Date';
	text-align:center;}
.xl31
	{mso-style-parent:style0;
	text-align:center;
	border-top:none;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl32
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:none;
	border-left:.5pt solid windowtext;}
.xl33
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl34
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:none;
	border-left:.5pt solid windowtext;}
.xl35
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl36
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl37
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl38
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl39
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;}
.xl40
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:none;
	border-left:none;}	
ruby
	{ruby-align:left;}
rt
	{color:windowtext;
	font-size:9.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-char-type:none;
	display:none;}
-->
</style>
<!--[if gte mso 9]><xml>
 <x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:Name>Sheet1</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:Print>
      <x:ValidPrinterInfo/>
      <x:PaperSizeIndex>9</x:PaperSizeIndex>
      <x:HorizontalResolution>600</x:HorizontalResolution>
      <x:VerticalResolution>600</x:VerticalResolution>
     </x:Print>
     <x:Selected/>
     <x:LeftColumnVisible>2</x:LeftColumnVisible>
     <x:Panes>
      <x:Pane>
       <x:Number>3</x:Number>
       <x:ActiveRow>7</x:ActiveRow>
       <x:ActiveCol>2</x:ActiveCol>
       <x:RangeSelection>$C$8:$N$8</x:RangeSelection>
      </x:Pane>
     </x:Panes>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet2</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet3</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
  <x:WindowHeight>8100</x:WindowHeight>
  <x:WindowWidth>12780</x:WindowWidth>
  <x:WindowTopX>360</x:WindowTopX>
  <x:WindowTopY>90</x:WindowTopY>
  <x:ProtectStructure>False</x:ProtectStructure>
  <x:ProtectWindows>False</x:ProtectWindows>
 </x:ExcelWorkbook>
</xml><![endif]-->
</head>

<body link=blue vlink=purple>

<table x:str border=0 cellpadding=0 cellspacing=0 width=992 style='border-collapse:
 collapse;table-layout:fixed;width:746pt'>
 <col width=109 style='mso-width-source:userset;mso-width-alt:3488;width:82pt'>
 <col width=83 style='mso-width-source:userset;mso-width-alt:2656;width:62pt'>
 <col width=47 style='mso-width-source:userset;mso-width-alt:1504;width:35pt'>
 <col width=81 style='mso-width-source:userset;mso-width-alt:2592;width:61pt'>
 <col width=53 style='mso-width-source:userset;mso-width-alt:1696;width:40pt'>
 <col width=55 style='mso-width-source:userset;mso-width-alt:1760;width:41pt'>
 <col width=77 span=2 style='mso-width-source:userset;mso-width-alt:2464;
 width:58pt'>
 <col width=53 style='mso-width-source:userset;mso-width-alt:1696;width:40pt'>
 <col width=81 style='mso-width-source:userset;mso-width-alt:2592;width:61pt'>
 <col width=58 style='mso-width-source:userset;mso-width-alt:1856;width:44pt'>
 <col width=56 style='mso-width-source:userset;mso-width-alt:1792;width:42pt'>
 <col width=84 style='mso-width-source:userset;mso-width-alt:2688;width:63pt'>
 <col width=78 style='mso-width-source:userset;mso-width-alt:2496;width:59pt'>
 <tr height=32 style='mso-height-source:userset;height:24.0pt'>
  <td colspan=14 height=32 class=xl29 width=992 style='height:24.0pt;
  width:746pt'>三分厂费用归集分配表</td>
 </tr>
 <tr height=19 style='height:14.25pt'>
  <td height=19 colspan=5 style='height:14.25pt;mso-ignore:colspan'></td>
  <td colspan=4 class=xl30 >@填报日期</td>
  <td colspan=5 style='mso-ignore:colspan'></td>
 </tr>
 <tr height=19 style='height:14.25pt'>
  <td height=19 colspan=10 style='height:14.25pt;mso-ignore:colspan'></td>
  <td colspan=3 class=xl31>单位:元</td>
  <td></td>
 </tr>
 <tr height=23 style='mso-height-source:userset;height:17.25pt'>
  <td rowspan=2 height=44 class=xl32 style='border-bottom:.5pt solid black;
  height:33.0pt'>项目</td>
  <td rowspan=2 class=xl34 style='border-bottom:.5pt solid black'>合计</td>
  <td colspan=6 class=xl37 style='border-right:.5pt solid black;border-left:
  none'>套管</td>
  <td colspan=6 class=xl37 style='border-right:.5pt solid black;border-left:
  none'>　</td>
 </tr>
 <tr height=21 style='mso-height-source:userset;height:15.75pt'>
  <td height=21 class=xl25 style='height:15.75pt'>数量</td>
  <td class=xl25>金额</td>
  <td class=xl25>单位费用</td>
  <td class=xl25>累计数量</td>
  <td class=xl25>累计金额</td>
  <td class=xl25>累计单位费用</td>
  <td class=xl25>数量</td>
  <td class=xl25>金额</td>
  <td class=xl25>单位费用</td>
  <td class=xl25>累计数量</td>
  <td class=xl25>累计金额</td>
  <td class=xl25>累计单位费用</td>
 </tr>";
        string part3 = @" 
 <![if supportMisalignedColumns]>
 <tr height=0 style='display:none'>
  <td width=109 style='width:82pt'></td>
  <td width=83 style='width:62pt'></td>
  <td width=47 style='width:35pt'></td>
  <td width=81 style='width:61pt'></td>
  <td width=53 style='width:40pt'></td>
  <td width=55 style='width:41pt'></td>
  <td width=77 style='width:58pt'></td>
  <td width=77 style='width:58pt'></td>
  <td width=53 style='width:40pt'></td>
  <td width=81 style='width:61pt'></td>
  <td width=58 style='width:44pt'></td>
  <td width=56 style='width:42pt'></td>
  <td width=84 style='width:63pt'></td>
  <td width=78 style='width:59pt'></td>
 </tr>
 <![endif]>
</table>"; 
        Response.Charset = "utf-8";
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        Response.ContentType = "application/ms-excel";
        Response.AddHeader("content-disposition", "attachment; filename=\"" + Server.UrlEncode("三分厂费用分配表") + ".xls\"");
        Response.Write(part1.Replace("@填报日期",DateTime.Now.ToString("yyyy年MM月dd日")));

        SqlConnection Conn = new SqlConnection();
        Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
        Conn.Open();
        SqlCommand Cmd = new SqlCommand();
        Cmd.Connection = Conn;
         string sql="";
       DataSet ds = new DataSet();
       string sqlpartCount = @"
       select 财务处.value('count(/root/rnode[1]/*)','int') from test where 分厂=3 and year=@年度 and month=@月份
       select 财务处.value('count(/root/rnode[2]/*)','int') from test where 分厂=3 and year=@年度 and month=@月份
       select 财务处.value('count(/root/rnode[3]/*)','int') from test where 分厂=3 and year=@年度 and month=@月份
       select 财务处.value('count(/root/rnode[4]/*)','int') from test where 分厂=3 and year=@年度 and month=@月份";
       sqlpartCount = sqlpartCount.Replace("@年度", this.Year.Text);
       sqlpartCount = sqlpartCount.Replace("@月份", this.Month.Text);
       SqlDataAdapter sda = new SqlDataAdapter(sqlpartCount, Conn);
       sda.Fill(ds);
       DataTable dt1 = ds.Tables[0];
       DataTable dt2 = ds.Tables[1];
       DataTable dt3 = ds.Tables[2];
       DataTable dt4 = ds.Tables[3];
       try
       {
           part1Count = int.Parse(dt1.Rows[0][0].ToString());

           part2Count = int.Parse(dt2.Rows[0][0].ToString());

           part3Count = int.Parse(dt3.Rows[0][0].ToString());

           part4Count = int.Parse(dt4.Rows[0][0].ToString());
       }
       catch
       {
           part1Count = 0;

           part2Count = 0;

           part3Count = 0;

           part4Count = 0;
       }
        //part1
        string str1 = @"
select '一、'+财务处.value('(/root/rnode/@name)[1]','nvarchar(10)')
,财务处.value('(/root/rnode/@cash)[1]','float')
,round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,财务处.value('(/root/rnode/@cash)[1]','float') as 合计
,round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,TJ55
,(select isnull(sum(TJ55),0) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,YJ55
,(select isnull(sum(YJ55),0) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
from test where year=@年度 and  分厂=3 and month=@月份 ";
        string sql1 = "";
        for (int i = 0; i < part1Count; i++)
        {
            sql1 += @"union all
          select 财务处.value('(/root/rnode[1]/node/@name)[@i]','nvarchar(10)')
,财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')
,round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),@月份)/TJ55,@月份)
,(select sum(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
,round((select sum(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
,round((select sum(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,0 as 合计
,0 
,0
,0
,0
,0 
,0
,0
,0
,0
,0
,0
,0
from test where year=@年度 and  分厂=3 and month=@月份 
             ";
            sql1 = sql1.Replace("@i", (i + 1).ToString());
        }
        //part2
        string str2 = @"union all select '二、'+财务处.value('(/root/rnode/@name)[2]','nvarchar(10)')
,财务处.value('(/root/rnode/@cash)[2]','float')
,round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,财务处.value('(/root/rnode/@cash)[2]','float') as 合计
,round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,0
,0
,0
,0
from test where year=@年度 and  分厂=3 and month=@月份 ";
        string sql2 = "";
        for (int i = 0; i < part2Count; i++)
        {
            sql2 += @"union all
          select 财务处.value('(/root/rnode[2]/node/@name)[@i]','nvarchar(10)')
,财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')
,round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
,round((select sum(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
,round((select sum(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,0 as 合计
,0 
,0
,0
,0
,0 
,0
,0
,0
,0
,0
,0
,0
from test where year=@年度 and  分厂=3 and month=@月份 
             ";
            sql2 = sql2.Replace("@i", (i + 1).ToString());
        }
        string str3 = @"union all select '三、'+财务处.value('(/root/rnode/@name)[3]','nvarchar(10)')
,财务处.value('(/root/rnode/@cash)[3]','float')
,round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,财务处.value('(/root/rnode/@cash)[3]','float') as 合计
,round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,0
,0
,0
,0
from test where year=@年度 and  分厂=3 and month=@月份 ";
        string sql3 = "";
        for (int i = 0; i < part3Count; i++)
        {
            sql3 += @"union all
          select 财务处.value('(/root/rnode[3]/node/@name)[@i]','nvarchar(10)')
,财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')
,round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
,round((select sum(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
,round((select sum(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,0 as 合计
,0 
,0
,0
,0
,0 
,0
,0
,0
,0
,0
,0
,0
from test where year=@年度 and  分厂=3 and month=@月份 
             ";
            sql3 = sql3.Replace("@i", (i + 1).ToString());
        }
        string str4 = @"union all select '四、'+财务处.value('(/root/rnode/@name)[4]','nvarchar(10)')
,财务处.value('(/root/rnode/@cash)[4]','float')
,round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,财务处.value('(/root/rnode/@cash)[4]','float') as 合计
,round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,0
,0
,0
,0
from test where year=@年度 and  分厂=3 and month=@月份 ";
        string sql4 = "";
        for (int i = 0; i < part4Count; i++)
        {
            sql4 += @"union all
          select 财务处.value('(/root/rnode[4]/node/@name)[@i]','nvarchar(10)')
,财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')
,round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
,round((select sum(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
,round((select sum(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,0 as 合计
,0 
,0
,0
,0
,0 
,0
,0
,0
,0
,0
,0
,0
from test where year=@年度 and  分厂=3 and month=@月份 
             ";
            sql4 = sql4.Replace("@i", (i + 1).ToString());
        }
        sql = str1 + sql1 + str2 + sql2 + str3 + sql3 + str4 + sql4;
        sql = sql.Replace("@年度", this.Year.Text);
        sql = sql.Replace("@月份", this.Month.Text);
         Cmd.CommandText = sql;
           
            SqlDataReader Reader = Cmd.ExecuteReader();
            try
            {               
                while (Reader.Read())
                    {
                        合计 += double.Parse(Reader[10].ToString());
                        套管金额合计 += double.Parse(Reader[11].ToString());
                        套管单位费用合计 += double.Parse(Reader[12].ToString());
                        套管累计金额合计 += double.Parse(Reader[13].ToString());
                        套管累计单位费用合计 += double.Parse(Reader[14].ToString());
                        油管金额合计 += double.Parse(Reader[15].ToString());
                        油管单位费用合计 += double.Parse(Reader[16].ToString());
                        油管累计金额合计 += double.Parse(Reader[17].ToString());
                        油管累计单位费用合计 += double.Parse(Reader[18].ToString());

                        套管产量 += double.Parse(Reader[19].ToString());
                        套管累计产量 += double.Parse(Reader[20].ToString());
                        油管产量 += double.Parse(Reader[21].ToString());
                        油管累计产量 += double.Parse(Reader[22].ToString());   
                     Response.Write("<tr height=19 style='height:14.25pt'><td height=19 class=xl26 style='height:14.25pt'>"+Reader[0]+"</td>");
                     Response.Write("<td class=xl27 >"+Reader[1]+"</td>");
                     Response.Write("<td class=xl27 ></td>");
                     Response.Write("<td class=xl27 >"+Reader[2]+"</td>");
                     Response.Write("<td class=xl28 >"+Reader[3]+"</td>");
                     Response.Write("<td class=xl27 ></td>");
                     Response.Write("<td class=xl27 >"+Reader[4]+"</td>");
                     Response.Write("<td class=xl28 >"+Reader[5]+"</td>");
                     Response.Write("<td class=xl27 ></td>");
                     Response.Write("<td class=xl27 >"+Reader[6]+"</td>");
                     Response.Write("<td class=xl28 >"+Reader[7]+"</td>");
                     Response.Write("<td class=xl27 ></td>");
                     Response.Write("<td class=xl27 >"+Reader[8]+"</td>");
                     Response.Write("<td class=xl27 >"+Reader[9]+"</td></tr>"); 
                    }          
                    Response.Write("<tr height=19 style='height:14.25pt'><td height=19 class=xl26 style='height:14.25pt'>合计</td>");
                    Response.Write("<td class=xl27 >"+合计+"</td>");
                    Response.Write("<td class=xl27 ></td>");
                    Response.Write("<td class=xl27 >"+套管金额合计+"</td>");
                    Response.Write("<td class=xl28 >"+套管单位费用合计+"</td>");
                    Response.Write("<td class=xl27 ></td>");
                    Response.Write("<td class=xl27 >"+套管累计金额合计+"</td>");
                    Response.Write("<td class=xl28 >"+套管累计单位费用合计+"</td>");
                    Response.Write("<td class=xl27 ></td>");
                    Response.Write("<td class=xl27 >"+油管金额合计+"</td>");
                    Response.Write("<td class=xl28 >"+油管单位费用合计+"</td>");
                    Response.Write("<td class=xl27 ></td>");
                    Response.Write("<td class=xl27 >"+油管累计金额合计+"</td>");
                    Response.Write("<td class=xl27 >"+油管累计单位费用合计+"</td></tr>");  
                    Response.Write("<tr height=19 style='height:14.25pt'><td height=19 class=xl26 style='height:14.25pt'>产量</td>"); 
                    Response.Write("<td class=xl27 ></td>");
                    Response.Write("<td class=xl27 >"+套管产量+"</td>");
                    Response.Write("<td class=xl27 ></td>");
                    Response.Write("<td class=xl28 ></td>");
                    Response.Write("<td class=xl27 >"+套管累计产量+"</td>");
                    Response.Write("<td class=xl27 ></td>");
                    Response.Write("<td class=xl28 ></td>");
                    Response.Write("<td class=xl27 >"+油管产量+"</td>");
                    Response.Write("<td class=xl27 ></td>");
                    Response.Write("<td class=xl28 ></td>");
                    Response.Write("<td class=xl27 >"+油管累计产量+"</td>");
                    Response.Write("<td class=xl27 ></td>");
                    Response.Write("<td class=xl27 ></td></br>");

                    Response.Write(" <tr height=26 style='mso-height-source:userset;height:19.5pt'><td height=26 style='height:19.5pt'></td><td colspan=3 class=xl40>单位负责人:魏 君</td>");
                    Response.Write("<td class=xl39 style='border-top:none'>　</td>");
                    Response.Write("<td class=xl39 style='border-top:none'>　</td>");
                    Response.Write("<td colspan=4 style='mso-ignore:colspan'></td><td colspan=3 class=xl40>制表:陈 霞</td>");
                    Response.Write("<td></td></tr>");
                    Conn.Close();
                    Response.Write(part3);
                    Response.End();
            }
            catch (Exception ex)
            {
                this.Message.Text="请输入套管或油管产量!";
                return;
            }
    }
 </script>
    <script type="text/javascript" language="javascript" src="/common.js"></script>
   <form id="form1" runat="server">  
      <div id="wintop" class="wintop"><span lang="zh-cn">三分厂费用归集分配表</span></div>
        <asp:Panel ID="Panel1" runat="server" CssClass="panel" Height="36px" >   
              年份：<asp:DropDownList ID="Year" runat="server">         
            <asp:ListItem>2010</asp:ListItem>
            <asp:ListItem>2011</asp:ListItem>
            <asp:ListItem>2012</asp:ListItem>
            <asp:ListItem>2013</asp:ListItem>
            <asp:ListItem>2014</asp:ListItem>
            <asp:ListItem>2015</asp:ListItem>   
            <asp:ListItem>2016</asp:ListItem>
            <asp:ListItem>2017</asp:ListItem>
            <asp:ListItem>2018</asp:ListItem>
            <asp:ListItem>2019</asp:ListItem>
            <asp:ListItem>2020</asp:ListItem>                
            </asp:DropDownList>
            <span lang="zh-cn">&nbsp;月份：</span><asp:DropDownList ID="Month" runat="server">
                <asp:ListItem>1</asp:ListItem>
                <asp:ListItem>2</asp:ListItem>
                <asp:ListItem>3</asp:ListItem>
                <asp:ListItem>4</asp:ListItem>
                <asp:ListItem>5</asp:ListItem>
                <asp:ListItem>6</asp:ListItem>
                <asp:ListItem>7</asp:ListItem>
                <asp:ListItem>8</asp:ListItem>
                <asp:ListItem>9</asp:ListItem>
                <asp:ListItem>10</asp:ListItem>
                <asp:ListItem>11</asp:ListItem>
                <asp:ListItem>12</asp:ListItem>
            </asp:DropDownList>
      <span lang="zh-cn">&nbsp;&nbsp;</span><asp:Button ID="Button_Query"
            runat="server" Text="查看报表" CssClass="button" UseSubmitBehavior="true" onclick="Button_Query_Click" 
             />            
            &nbsp;<asp:Button ID="Button1" runat="server" class="button" onclick="Button1_Click" 
                Text="导 出" />
      </asp:Panel>
        <asp:Panel ID="Panel2" runat="server" CssClass="panel2">
        <asp:Label ID="Message" runat="server" Text="·准备就绪" CssClass="prompt" Visible="True"></asp:Label>
        </asp:Panel> 
     <div align="center">
<style>
<!--table
	{mso-displayed-decimal-separator:"\.";
	mso-displayed-thousand-separator:"\,";}
@page
	{margin:.13in .1in 1.0in .41in;
	mso-header-margin:.18in;
	mso-footer-margin:.5in;
	mso-page-orientation:landscape;}
tr
	{mso-height-source:auto;
	mso-ruby-visibility:none;}
col
	{mso-width-source:auto;
	mso-ruby-visibility:none;}
br
	{mso-data-placement:same-cell;}
.style0
	{mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	white-space:nowrap;
	mso-rotate:0;
	mso-background-source:auto;
	mso-pattern:auto;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	border:none;
	mso-protection:locked visible;
	mso-style-name:常规;
	mso-style-id:0;}
td
	{mso-style-parent:style0;
	padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	border:none;
	mso-background-source:auto;
	mso-pattern:auto;
	mso-protection:locked visible;
	white-space:nowrap;
	mso-rotate:0;}
.xl24
	{mso-style-parent:style0;
	text-align:center;}
.xl25
	{mso-style-parent:style0;
	font-size:18.0pt;
	text-align:center;
	vertical-align:bottom;}
.xl26
	{mso-style-parent:style0;
	mso-number-format:"Long Date";
	text-align:center;}
.xl27
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;
	border:.5pt solid windowtext;}
.xl28
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border:.5pt solid windowtext;}
.xl29
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border:.5pt solid windowtext;}
.xl30
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:right;
	border:.5pt solid windowtext;}
.xl31
	{mso-style-parent:style0;
	font-size:10.0pt;}
ruby
	{ruby-align:left;}
rt
	{color:windowtext;
	font-size:9.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-char-type:none;
	display:none;}
-->
</style>

<body link=blue vlink=purple>
<table x:str border=0 cellpadding=0 cellspacing=0 width=992 style='border-collapse:
 collapse;table-layout:fixed;width:746pt'>
 <col width=109 style='mso-width-source:userset;mso-width-alt:3488;width:82pt'>
 <col width=83 style='mso-width-source:userset;mso-width-alt:2656;width:62pt'>
 <col width=47 style='mso-width-source:userset;mso-width-alt:1504;width:35pt'>
 <col width=81 style='mso-width-source:userset;mso-width-alt:2592;width:61pt'>
 <col width=53 style='mso-width-source:userset;mso-width-alt:1696;width:40pt'>
 <col width=55 style='mso-width-source:userset;mso-width-alt:1760;width:41pt'>
 <col width=77 span=2 style='mso-width-source:userset;mso-width-alt:2464;
 width:58pt'>
 <col width=53 style='mso-width-source:userset;mso-width-alt:1696;width:40pt'>
 <col width=81 style='mso-width-source:userset;mso-width-alt:2592;width:61pt'>
 <col width=58 style='mso-width-source:userset;mso-width-alt:1856;width:44pt'>
 <col width=56 style='mso-width-source:userset;mso-width-alt:1792;width:42pt'>
 <col width=84 style='mso-width-source:userset;mso-width-alt:2688;width:63pt'>
 <col width=78 style='mso-width-source:userset;mso-width-alt:2496;width:59pt'>
 <tr height=32 style='mso-height-source:userset;height:24.0pt'>
  <td colspan=14 height=32 class=xl25 width=992 style='height:24.0pt;
  width:746pt'>三分厂费用归集分配表</td>
 </tr>
 <tr height=19 style='height:14.25pt'>
  <td height=19 colspan=5 style='height:14.25pt;mso-ignore:colspan'></td>
  <td colspan=4 class=xl26 x:num="40850">2011年11月3日</td>
  <td colspan=5 style='mso-ignore:colspan'></td>
 </tr>
 <tr height=19 style='height:14.25pt'>
  <td height=19 colspan=10 style='height:14.25pt;mso-ignore:colspan'></td>
  <td colspan=3 class=xl24>单位:元</td>
  <td></td>
 </tr>
 <tr height=23 style='mso-height-source:userset;height:17.25pt'>
  <td rowspan=2 height=44 class=xl28 style='height:33.0pt'>项目</td>
  <td rowspan=2 class=xl27>合计</td>
  <td colspan=6 class=xl28 style='border-left:none'>套管</td>
  <td colspan=6 class=xl28 style='border-left:none'>　油管</td>
 </tr>
 <tr height=21 style='mso-height-source:userset;height:15.75pt'>
  <td height=21 class=xl27 style='height:15.75pt;border-top:none;border-left:
  none'>数量</td>
  <td class=xl27 style='border-top:none;border-left:none'>金额</td>
  <td class=xl27 style='border-top:none;border-left:none'>单位费用</td>
  <td class=xl27 style='border-top:none;border-left:none'>累计数量</td>
  <td class=xl27 style='border-top:none;border-left:none'>累计金额</td>
  <td class=xl27 style='border-top:none;border-left:none'>累计单位费用</td>
  <td class=xl27 style='border-top:none;border-left:none'>数量</td>
  <td class=xl27 style='border-top:none;border-left:none'>金额</td>
  <td class=xl27 style='border-top:none;border-left:none'>单位费用</td>
  <td class=xl27 style='border-top:none;border-left:none'>累计数量</td>
  <td class=xl27 style='border-top:none;border-left:none'>累计金额</td>
  <td class=xl27 style='border-top:none;border-left:none'>累计单位费用</td>
 </tr>
  <%         
        SqlConnection Conn = new SqlConnection();
        Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
        Conn.Open();
        SqlCommand Cmd = new SqlCommand();
        Cmd.Connection = Conn;
        string sql="";
       DataSet ds = new DataSet();
       string sqlpartCount = @"
       select 财务处.value('count(/root/rnode[1]/*)','int') from test where 分厂=3 and year=@年度 and month=@月份
       select 财务处.value('count(/root/rnode[2]/*)','int') from test where 分厂=3 and year=@年度 and month=@月份
       select 财务处.value('count(/root/rnode[3]/*)','int') from test where 分厂=3 and year=@年度 and month=@月份
       select 财务处.value('count(/root/rnode[4]/*)','int') from test where 分厂=3 and year=@年度 and month=@月份";
       sqlpartCount = sqlpartCount.Replace("@年度", this.Year.Text);
       sqlpartCount = sqlpartCount.Replace("@月份", this.Month.Text);
       SqlDataAdapter sda = new SqlDataAdapter(sqlpartCount, Conn);
       sda.Fill(ds);
       DataTable dt1 = ds.Tables[0];
       DataTable dt2 = ds.Tables[1];
       DataTable dt3 = ds.Tables[2];
       DataTable dt4 = ds.Tables[3];
       try
       {
           part1Count = int.Parse(dt1.Rows[0][0].ToString());

           part2Count = int.Parse(dt2.Rows[0][0].ToString());

           part3Count = int.Parse(dt3.Rows[0][0].ToString());

           part4Count = int.Parse(dt4.Rows[0][0].ToString());
       }
       catch
       {
           part1Count = 0;

           part2Count = 0;

           part3Count = 0;

           part4Count = 0;
       }
        //part1
        string str1 = @"
select '一、'+财务处.value('(/root/rnode/@name)[1]','nvarchar(10)')
,财务处.value('(/root/rnode/@cash)[1]','float')
,round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,财务处.value('(/root/rnode/@cash)[1]','float') as 合计
,round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[1]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,TJ55
,(select isnull(sum(TJ55),0) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,YJ55
,(select isnull(sum(YJ55),0) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
from test where year=@年度 and  分厂=3 and month=@月份 ";
        string sql1 = "";
        for (int i = 0; i < part1Count; i++)
        {
            sql1 += @"union all
          select 财务处.value('(/root/rnode[1]/node/@name)[@i]','nvarchar(10)')
,财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')
,round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),@月份)/TJ55,@月份)
,(select sum(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
,round((select sum(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
,round((select sum(round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,0 as 合计
,0 
,0
,0
,0
,0 
,0
,0
,0
,0
,0
,0
,0
from test where year=@年度 and  分厂=3 and month=@月份 
             ";
            sql1 = sql1.Replace("@i", (i + 1).ToString());
        }
        //part2
        string str2 = @"union all select '二、'+财务处.value('(/root/rnode/@name)[2]','nvarchar(10)')
,财务处.value('(/root/rnode/@cash)[2]','float')
,round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,财务处.value('(/root/rnode/@cash)[2]','float') as 合计
,round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[2]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,0
,0
,0
,0
from test where year=@年度 and  分厂=3 and month=@月份 ";
        string sql2 = "";
        for (int i = 0; i < part2Count; i++)
        {
            sql2 += @"union all
          select 财务处.value('(/root/rnode[2]/node/@name)[@i]','nvarchar(10)')
,财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')
,round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
,round((select sum(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
,round((select sum(round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,0 as 合计
,0 
,0
,0
,0
,0 
,0
,0
,0
,0
,0
,0
,0
from test where year=@年度 and  分厂=3 and month=@月份 
             ";
            sql2 = sql2.Replace("@i", (i + 1).ToString());
        }
        string str3 = @"union all select '三、'+财务处.value('(/root/rnode/@name)[3]','nvarchar(10)')
,财务处.value('(/root/rnode/@cash)[3]','float')
,round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,财务处.value('(/root/rnode/@cash)[3]','float') as 合计
,round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[3]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,0
,0
,0
,0
from test where year=@年度 and  分厂=3 and month=@月份 ";
        string sql3 = "";
        for (int i = 0; i < part3Count; i++)
        {
            sql3 += @"union all
          select 财务处.value('(/root/rnode[3]/node/@name)[@i]','nvarchar(10)')
,财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')
,round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
,round((select sum(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
,round((select sum(round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,0 as 合计
,0 
,0
,0
,0
,0 
,0
,0
,0
,0
,0
,0
,0
from test where year=@年度 and  分厂=3 and month=@月份 
             ";
            sql3 = sql3.Replace("@i", (i + 1).ToString());
        }
        string str4 = @"union all select '四、'+财务处.value('(/root/rnode/@name)[4]','nvarchar(10)')
,财务处.value('(/root/rnode/@cash)[4]','float')
,round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,财务处.value('(/root/rnode/@cash)[4]','float') as 合计
,round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)
,round((select sum(round(财务处.value('(/root/rnode/@cash)[4]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,0
,0
,0
,0
from test where year=@年度 and  分厂=3 and month=@月份 ";
        string sql4 = "";
        for (int i = 0; i < part4Count; i++)
        {
            sql4 += @"union all
          select 财务处.value('(/root/rnode[4]/node/@name)[@i]','nvarchar(10)')
,财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')
,round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)/TJ55,2)
,(select sum(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
,round((select sum(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(TJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(TJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)
,round(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)/YJ55,2)
,(select sum(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份) 
,round((select sum(round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')*(YJ55/(TJ55+YJ55)),2)) from test where year=@年度 and  分厂=3 and month between 1 and @月份)/(select sum(YJ55) from test where year=@年度 and  分厂=3 and month between 1 and @月份),2)
,0 as 合计
,0 
,0
,0
,0
,0 
,0
,0
,0
,0
,0
,0
,0
from test where year=@年度 and  分厂=3 and month=@月份 
             ";
            sql4 = sql4.Replace("@i", (i + 1).ToString());
        }
        sql = str1 + sql1 + str2 + sql2 + str3 + sql3 + str4 + sql4;
        sql = sql.Replace("@年度", this.Year.Text);
        sql = sql.Replace("@月份", this.Month.Text);
         Cmd.CommandText = sql;
           
            SqlDataReader Reader = Cmd.ExecuteReader();
            try
            {               
                while (Reader.Read())
                    {
                        合计 += double.Parse(Reader[10].ToString());
                        套管金额合计 += double.Parse(Reader[11].ToString());
                        套管单位费用合计 += double.Parse(Reader[12].ToString());
                        套管累计金额合计 += double.Parse(Reader[13].ToString());
                        套管累计单位费用合计 += double.Parse(Reader[14].ToString());
                        油管金额合计 += double.Parse(Reader[15].ToString());
                        油管单位费用合计 += double.Parse(Reader[16].ToString());
                        油管累计金额合计 += double.Parse(Reader[17].ToString());
                        油管累计单位费用合计 += double.Parse(Reader[18].ToString());

                        套管产量 += double.Parse(Reader[19].ToString());
                        套管累计产量 += double.Parse(Reader[20].ToString());
                        油管产量 += double.Parse(Reader[21].ToString());
                        油管累计产量 += double.Parse(Reader[22].ToString());
                    %>
                <tr height=19 style='height:14.25pt'>
  <td height=19 class=xl29 style='height:14.25pt;border-top:none'><%=Reader[0]%></td>
  <td class=xl30 style='border-top:none;border-left:none'><%=Reader[1]%></td>
  <td class=xl30 style='border-top:none;border-left:none'> </td>
  <td class=xl30 style='border-top:none;border-left:none'><%=Reader[2]%></td>
  <td class=xl28 style='border-top:none;border-left:none'><%=Reader[3]%></td>
  <td class=xl30 style='border-top:none;border-left:none'>　</td>
  <td class=xl30 style='border-top:none;border-left:none'><%=Reader[4]%></td>
  <td class=xl28 style='border-top:none;border-left:none'><%=Reader[5]%></td> 
  <td class=xl30 style='border-top:none;border-left:none'>　</td>
  <td class=xl30 style='border-top:none;border-left:none'><%=Reader[6]%></td>
  <td class=xl30 style='border-top:none;border-left:none'><%=Reader[7]%></td>
  <td class=xl30 style='border-top:none;border-left:none'>　</td>
  <td class=xl30 style='border-top:none;border-left:none'><%=Reader[8]%></td>
  <td class=xl30 style='border-top:none;border-left:none'><%=Reader[9]%></td>
 </tr>                   
              <%  
                 }
                 
              %>                         

  <tr height=19 style='height:14.25pt'>
  <td height=19 class=xl29 style='height:14.25pt;border-top:none'>合计</td>
  <td class=xl30 style='border-top:none;border-left:none'><%=合计%></td>
  <td class=xl30 style='border-top:none;border-left:none'> </td>
  <td class=xl30 style='border-top:none;border-left:none'><%=套管金额合计%></td>
  <td class=xl28 style='border-top:none;border-left:none'><%=套管单位费用合计%></td>
  <td class=xl30 style='border-top:none;border-left:none'>　</td>
  <td class=xl30 style='border-top:none;border-left:none'><%=套管累计金额合计%></td>
  <td class=xl28 style='border-top:none;border-left:none'><%=套管累计单位费用合计%></td> 
  <td class=xl30 style='border-top:none;border-left:none'>　</td>
  <td class=xl30 style='border-top:none;border-left:none'><%=油管金额合计%></td>
  <td class=xl30 style='border-top:none;border-left:none'><%=油管单位费用合计%></td>
  <td class=xl30 style='border-top:none;border-left:none'>　</td>
  <td class=xl30 style='border-top:none;border-left:none'><%=油管累计金额合计%></td>
  <td class=xl30 style='border-top:none;border-left:none'><%=油管累计单位费用合计%></td>
 </tr>   
  <tr height=19 style='height:14.25pt'>
  <td height=19 class=xl29 style='height:14.25pt;border-top:none'>产量</td>
  <td class=xl30 style='border-top:none;border-left:none'> </td>
  <td class=xl30 style='border-top:none;border-left:none'><%=套管产量%> </td>
  <td class=xl30 style='border-top:none;border-left:none'></td>
  <td class=xl28 style='border-top:none;border-left:none'></td>
  <td class=xl30 style='border-top:none;border-left:none'><%=套管累计产量%></td>
  <td class=xl30 style='border-top:none;border-left:none'></td>
  <td class=xl28 style='border-top:none;border-left:none'></td> 
  <td class=xl30 style='border-top:none;border-left:none'><%=油管产量%></td>
  <td class=xl30 style='border-top:none;border-left:none'></td>
  <td class=xl30 style='border-top:none;border-left:none'></td>
  <td class=xl30 style='border-top:none;border-left:none'><%=油管累计产量%></td>
  <td class=xl30 style='border-top:none;border-left:none'></td>
  <td class=xl30 style='border-top:none;border-left:none'></td>
 </tr>  
 <tr height=19 style='height:14.25pt'>
  <td height=19 colspan=2 style='height:14.25pt;mso-ignore:colspan'></td>
  <td colspan=4 >单位负责人:魏 君</td>
  <td colspan=4 style='mso-ignore:colspan'></td>
  <td colspan=3 >制表:陈 霞</td>
  <td></td>
 </tr>
   <%           Reader.Close();
                Cmd.Clone();
                Conn.Close();
            }
            catch (Exception ex)
            {
                this.Message.Text="请输入套管或油管产量!";
                return;
            }
     %>                          
     </div>
    </form>
</body>
</html>
